<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

class PublicAction extends Action {
	// 菜单页面
	public function left() {
		$this->display();
	}
	
public function top() {
	date_default_timezone_set (PRC);
	$dayofweek=getdate(time());
	$weekDay = array(
		"Monday"=>"星期一",
		"Tuesday"=>"星期二",
		"Wednesday"=>"星期三",
		"Thursday"=>"星期四",
		"Friday"=>"星期五",
		"Saturday"=>"星期六",
		"Sunday"=>"星期日",
	);
	$info = array(
		'nowDate'=>gmdate("Y年n月j日 ",time()+8*3600)."&nbsp;&nbsp;".$weekDay[$dayofweek["weekday"]],
	);
	$this->assign("info",$info);
	$this->display();
	}
	
public function center() {
		$this->display();
	}
public function down() {
		$this->display();
	}

    // 后台首页 查看系统信息
    public function manframe() {
        $info = array(
            '操作系统'=>PHP_OS,
            '运行环境'=>$_SERVER["SERVER_SOFTWARE"],
            'PHP运行方式'=>php_sapi_name(),
            'ThinkPHP版本'=>THINK_VERSION.' [ <a href="http://thinkphp.cn" target="_blank">查看最新版本</a> ]',
            '上传附件限制'=>ini_get('upload_max_filesize'),
            '执行时间限制'=>ini_get('max_execution_time').'秒',
            '服务器时间'=>date("Y年n月j日 H:i:s"),
            '北京时间'=>gmdate("Y年n月j日 H:i:s",time()+8*3600),
            '服务器域名/IP'=>$_SERVER['SERVER_NAME'].' [ '.gethostbyname($_SERVER['SERVER_NAME']).' ]',
            '剩余空间'=>round((@disk_free_space(".")/(1024*1024)),2).'M',
            'register_globals'=>get_cfg_var("register_globals")=="1" ? "ON" : "OFF",
            'magic_quotes_gpc'=>(1===get_magic_quotes_gpc())?'YES':'NO',
            'magic_quotes_runtime'=>(1===get_magic_quotes_runtime())?'YES':'NO',
            );
        $this->assign('info',$info);
        $this->display();
    }

	// 用户登录页面
	public function login() {
		if(!isset($_SESSION[C('USER_AUTH_KEY')])) {
			$this->display();
		}else{
			$this->redirect('Index/index');
		}
	}

	public function index()
	{
		//如果通过认证跳转到首页
		redirect(__APP__);
	}

	// 用户登出
    public function logout()
    {
        if(isset($_SESSION['admin'])) {
			unset($_SESSION['admin']);
			unset($_SESSION);
			session_destroy();
            $this->redirect('Index');
        }
    }

	// 登录检测
	public function checkLogin() {
		if(empty($_POST['account'])) {
			$errmsg = '帐号错误！';
		}elseif (empty($_POST['password'])){
			$errmsg = '密码必须！';
		}
		if(!empty($errmsg)){
			$this->assign('account',$_POST['account']);
			$this->assign('errmsg',$errmsg);
			$this->display('login');
		}else{
			$User = M('Systems');
			$vo=$User->where("sys_id='".$_POST['account']."' and sys_password='".md5($_POST['password'])."'")->select();
			if ($vo){
				$_SESSION['admin']['account'] = $_POST['account'];
				$_SESSION['admin']['name'] = $vo[0]['user_name'];
				$this->redirect('Index');
			}else{
				$errmsg = '账号或者密码错误！';
				$this->assign('account',$_POST['account']);
				$this->assign('errmsg',$errmsg);
				$this->display('login');
			} 
		}
		
	}
    // 更换密码
    public function changePwd()
    {
		$this->checkUser();
        //对表单提交处理进行处理或者增加非表单数据
		if(md5($_POST['verify'])	!= $_SESSION['verify']) {
			$this->error('验证码错误！');
		}
		$map	=	array();
        $map['password']= pwdHash($_POST['oldpassword']);
        if(isset($_POST['account'])) {
            $map['account']	 =	 $_POST['account'];
        }elseif(isset($_SESSION[C('USER_AUTH_KEY')])) {
            $map['id']		=	$_SESSION[C('USER_AUTH_KEY')];
        }
        //检查用户
        $User    =   M("User");
        if(!$User->where($map)->field('id')->find()) {
            $this->error('旧密码不符或者用户名错误！');
        }else {
			$User->password	=	pwdHash($_POST['password']);
			$User->save();
			$this->success('密码修改成功！');
         }
    }
public function profile() {
		$this->checkUser();
		$User	 =	 M("User");
		$vo	=	$User->getById($_SESSION[C('USER_AUTH_KEY')]);
		$this->assign('vo',$vo);
		$this->display();
	}
	 public function verify()
    {
		$type	 =	 isset($_GET['type'])?$_GET['type']:'gif';
        import("@.ORG.Image");
        Image::buildImageVerify(4,1,$type);
    }

}
?>